import java.util.ArrayList;
import java.util.List;

public class Binary {
    public static void main(String[] args) {
        int[] arr={1,3,3,4,34,50};
        List<Integer> list=Search(arr,0,arr.length-1,3);
        for (Integer list1:list) {
            System.out.println(list1+" ");
        }

    }
    public static List<Integer> Search(int[] arr,int left,int right,int values){
        if (left>right||values<arr[left]||values>arr[right]){
            return new ArrayList<>();
        }
        //int mid=(left+right)/2;
        int mid=left+(right-left)*(values-arr[left])/(arr[right]-arr[left]);
        System.out.println("插值");
        int val=arr[mid];
        if (values>val){
            return Search(arr,mid+1,right,values);
        } else if (values<val) {
            return Search(arr,left,mid-1,values);
        }else {
            List<Integer> arrayList = new ArrayList<>();
            int temp=mid-1;
            while (true){
                if (temp<0||arr[temp]!=values){
                    break;
                }
                arrayList.add(temp);
                temp-=1;
            }
            arrayList.add(mid);
            temp=mid+1;
            while (true){
                if (temp>arr.length-1||arr[temp]!=values){
                    break;
                }
                arrayList.add(temp);
                temp+=1;
            }
            return arrayList;
        }
    }
}
